package servlet;

import bean.Customer;
import dao.entity.CustomerDaoImpl_2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "customerAddServlet", value = "/cadd")
public class CustomerAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取数据
        String cid = (String) request.getParameter("cid");
        String cname = (String) request.getParameter("cname");
        String pwd = (String) request.getParameter("pwd");
        String gender = (String) request.getParameter("gender");
        String c_eamil = (String) request.getParameter("c_email");
        String c_phone = (String) request.getParameter("c_phone");
        String lg_time = (String) request.getParameter("lg_time");
        String c_status = (String) request.getParameter("c_status");
        //封装数据
        Customer c = new Customer(cid,cname,pwd,gender,c_eamil,c_phone,lg_time,c_status);
        //执行插入操作
        //int n = SHelper.addS(student);
        CustomerDaoImpl_2 cdi = new CustomerDaoImpl_2();
        int n = cdi.addCustomer(c);
        if(n!=0){
            //插入成功
            request.setAttribute("n",1);
        }else {
            //插入失败
            request.setAttribute("n",0);
        }
        request.getRequestDispatcher("result.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
